package mException;

//import com.sun.org.apache.regexp.internal.recompile;

/**
 * 2023-06-07 10:25:23
 * 结论：return 语句将会覆盖 try 或 catch 块中的 return 语句或抛出的异常。
 * <p>
 * return 覆盖 throw new RuntimeException("custom Exception....");不执行。
 */
public class Throw_Finally_CloseIO {

    public static void main(String[] args) {
        String result = null;
        try {
            result = getExceptionResult();
        } catch (Exception e) {
            System.out.println("main::::catch:");
            e.printStackTrace();
        }
        System.err.println("结果==" + result);//结果==CatchException or return "try catch 外return";


        try {
            getException();
        } catch (Exception e) {
            System.out.println("main::::catch:222");
            e.printStackTrace();
        }
    }


    //	private static String getExceptionResult() {//外层没有 没有接受到 Exception
    private static String getExceptionResult() throws Exception {
        try {
            int a = 1;
            int b = 0;
            System.out.println(a / b);
            return a / b + "";
        } catch (Exception e) {
            System.out.println("start throw:");
            throw e;//外层没有 没有接受到 Exception //java.lang.ArithmeticException: / by zero
        } finally {
            System.out.println("执行finally");
            return "finally";
        }
    }

    private static void getException() throws Exception {
        try {
            int a = 1;
            int b = 0;
            System.out.println(a / b);
            System.out.println("over:");
        } catch (Exception e) {
            System.out.println("start throw:");
            throw e;//外层没有 没有接受到 Exception //java.lang.ArithmeticException: / by zero
        } finally {
            System.out.println("执行finally");
        }
    }
}
